#ifndef SCENE_H
#define SCENE_H

#include <list>
#include <map>
#include <stdint.h>
#include <memory>

struct Entity;
typedef std::list<std::shared_ptr<Entity>> EntityList;
typedef std::map<uint32_t, std::shared_ptr<Entity>> EntityMap;

struct Entity {
    Entity(int id, int radius, int x, int y) : id(id), radius(radius), x(x), y(y) {}
    virtual ~Entity() = default;

    uint32_t id;
    uint32_t radius;
    int x;
    int y;

    std::list<std::shared_ptr<Entity>>::iterator x_pos;
    std::list<std::shared_ptr<Entity>>::iterator y_pos;
};


class Scene {
public:
    Scene() = default;
    virtual ~Scene();

    void add(uint32_t id, int x, int y, uint32_t radius = 2);
    void move(uint32_t id, int x, int y);
    void leave(uint32_t);

private:
    void getRangeSet(const std::shared_ptr<Entity>& entity, EntityMap& maps);
    void updateEntityPos(std::shared_ptr<Entity>& entity, int x, int y);

private:
    EntityMap m_entities;
    EntityList m_x_entities;
    EntityList m_y_entities;
};

#endif // SCENE_H
